﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Demo_Flexigrid_PostBack : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.Request.HttpMethod == "POST")
        {
            ResponseWrite_JSON();
        }
        else
        {
            if (!IsPostBack)
            {

            }
        }
    }

    private void ResponseWrite_JSON()
    {
        string page = Request.Form["page"];
        string rp = Request.Form["rp"];
        string sortname = Request.Form["sortname"];
        string sortorder = Request.Form["sortorder"];
        string query = Request.Form["query"];
        string qtype = Request.Form["qtype"];

        string sort = "";
        string where = "";


        if (string.IsNullOrWhiteSpace(sortname)) sortname = "name";
        if (string.IsNullOrWhiteSpace(sortorder)) sortorder = "desc";

        sort = string.Format("ORDER BY {0} {1}", sortname, sortorder);

        if (string.IsNullOrWhiteSpace(page)) page = "1";
        if (string.IsNullOrWhiteSpace(rp)) rp = "10";

        if (!string.IsNullOrWhiteSpace(query)) where = string.Format(" WHERE {0} LIKE '%{1}%' ", qtype, query);

        Response.AddHeader("Cache-Control", "no-cache, must-revalidate");
        Response.AddHeader("Pragma", "no-cache");
        Response.ContentType = "Content-type: text/x-json";

        Response.Write(@"{
                        page : 0,
                        total : 2,
                        rows : [
	                        {
		                        id : '1',
		                        cell : '2',
		                        name:'name',
		                        printable_name:'printable_name',
		                        iso3:'iso3',
		                        numcode:'2'
	                        },
	                        {
		                        id : '1',
		                        cell : '2',
		                        name:'name',
		                        printable_name:'printable_name',
		                        iso3:'iso3',
		                        numcode:'2'
	                        },
                        ]
                        }");
    }

}